home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / plstr.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  4KB  |  130 lines

  1. /* Prints out a "string" at reference position with physical         */
  2. /* coordinates (refx,refy). The coordinates of the vectors defining  */
  3. /* the string are passed through the linear mapping defined by the   */
  4. /* 2 x 2 matrix xform() before being plotted.                        */
  5. /* The reference position is at the left-hand edge of the string. If */
  6. /* base = 1, it is aligned with the baseline of the string. If       */
  7. /* base = 0, it is aligned with the centre of the character box.     */
  8.  
  9. /* Note, all calculations are done in terms of millimetres. These */
  10. /* are scaled as necessary before plotting the string on the page */
  11.  
  12. #include "plplot.h"
  13. #include <math.h>
  14.  
  15. void plstr(base,xform,refx,refy,string)
  16. int base, refx, refy;
  17. char *string;
  18. float xform[4];
  19. {
  20.       int symbol[256];
  21.       short int xygrid[300];
  22.       int ch, cx, cy, i, k, length, level, penup;
  23.       int xbase, ybase, ydisp, lx, ly, style;
  24.       int oline, uline;
  25.       float width, xorg, yorg, x, y, def, ht, dscale, scale;
  26.       float xscl, xoff, yscl, yoff;
  27.    
  28.       width = 0.0;
  29.       oline = 0;
  30.       uline = 0;
  31.  
  32.       gchr(&def,&ht);
  33.       dscale = 0.05*ht;
  34.       scale = dscale;
  35.       gmp(&xscl,&xoff,&yscl,&yoff);
  36.  
  37. /* Line style must be continuous */
  38.  
  39.       gnms(&style);
  40.       snms(0);
  41.       
  42.       pldeco(symbol,&length,string);
  43.       xorg = 0.0;
  44.       yorg = 0.0;
  45.       level = 0;
  46.  
  47.       for (i=0; i<length; i++)  {
  48.         ch = symbol[i];
  49.         if (ch == -1) {
  50.           level = level + 1;
  51.           yorg = yorg + 16.0 * scale;
  52.           scale = dscale * pow(0.75,(double)abs(level));
  53.         }
  54.         else if (ch == -2) {  
  55.           level = level - 1;
  56.           scale = dscale * pow(0.75,(double)abs(level));
  57.           yorg = yorg - 16.0 * scale;
  58.         }
  59.         else if (ch == -3)
  60.           xorg = xorg - width * scale;
  61.         else if (ch == -4)
  62.           oline = !oline;
  63.         else if (ch == -5) 
  64.           uline = !uline;
  65.         else  {
  66.           if (plcvec(ch,xygrid)) {
  67.             xbase = xygrid[3];
  68.             width = xygrid[4] - xbase;
  69.             if (base == 0) {
  70.               ybase = 0;
  71.               ydisp = xygrid[1];
  72.             }
  73.             else  {
  74.               ybase = xygrid[1];
  75.               ydisp = 0;
  76.             }
  77.             k = 5;
  78.             penup = 1;
  79. lab2:
  80.               cx = xygrid[k];
  81.               k = k+1;
  82.               cy = xygrid[k];
  83.               k = k+1;
  84.               if (cx == -64 && cy == -64) goto lab3;
  85.               if (cx == -64 && cy == 0) 
  86.                 penup = 1;
  87.               else {
  88.                 x = xorg + (cx - xbase) * scale;
  89.                 y = yorg + (cy - ybase) * scale;
  90.                 lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  91.                 ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  92.                 if (penup != 0) {
  93.                   movphy(lx,ly);
  94.                   penup = 0;
  95.                 }
  96.                 else
  97.                   draphy(lx,ly);
  98.               }
  99.             goto lab2;
  100. lab3:
  101.             if (oline) {
  102.               x = xorg;
  103.               y = yorg + (30+ydisp)*scale;
  104.               lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  105.               ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  106.               movphy(lx,ly);
  107.               x = xorg + width*scale;
  108.               lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  109.               ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  110.               draphy(lx,ly);
  111.             }
  112.             if (uline) {
  113.               x = xorg;
  114.               y = yorg + (-5+ydisp)*scale;
  115.               lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  116.               ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  117.               movphy(lx,ly);
  118.               x = xorg + width*scale;
  119.               lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  120.               ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  121.               draphy(lx,ly);
  122.             }
  123.             xorg = xorg + width*scale;
  124.           }
  125.         }
  126.       }
  127.       snms(style);
  128. }
  129.  
  130.